<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller;
use App\Libs\Oss;
use App\Libs\Cache;
class UserController extends AbstractController
{
    public function getAliyunUploadToken()
    {
        $key = 'aliyun_upload_token_token';
        $token_data = Cache::get($key);
        if ($token_data) {
            $expiration = strtotime($token_data['Credentials']['Expiration']);
            if (time()- 60*5 >= $expiration) {
                $token_data = Oss::getToken();
                Cache::set($key, $token_data);
            }
        }else{
            $token_data = Oss::getToken();
            Cache::set($key, $token_data);
        }

        $data = Oss::getSignature($token_data);
        return $this->success(['sign'=> $data, 'token'=> $token_data]);
    }
}
